package com.play.hibernate.model;

// Generated 12.07.2012 16:06:45 by Hibernate Tools 3.4.0.CR1

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;



/**
 * Frage generated by hbm2java
 */
@Entity
@Table(name="frage")
public class Frage implements java.io.Serializable {

	
	@Id 
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(unique=true, nullable=false)
	private Integer id;
	
	@ManyToOne
	@JoinColumn(name="userId")
	private User user;
	
	@Column(length=100)
	private String frage;
	
	@Column(length=4)
	private String typ;
	
	//bi-directional many-to-one association to Antwort
    @OneToMany(mappedBy="frage")
	private Set<Antwort> antworts = new HashSet<Antwort>(0);

	public Frage() {
	}

	public Frage(User user, String frage, String typ, Set antworts) {
		this.user = user;
		this.frage = frage;
		this.typ = typ;
		this.antworts = antworts;
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getFrage() {
		return this.frage;
	}

	public void setFrage(String frage) {
		this.frage = frage;
	}

	public String getTyp() {
		return this.typ;
	}

	public void setTyp(String typ) {
		this.typ = typ;
	}

	public Set getAntworts() {
		return this.antworts;
	}

	public void setAntworts(Set antworts) {
		this.antworts = antworts;
	}
	
	public void setOwner(User employee) {
        this.user = employee;
        if (!employee.getFrages().contains(this)) {
        	//oder addFrages(this)  bin mir nicht sicher.....kann ein fehler sein
        	//employee.getFrages().add(this);
            employee.addFrage(this);
        }
    }

}
